package com.nfcpay;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.cert.X509Certificate;

import javax.crypto.EncryptedPrivateKeyInfo;

import org.bouncycastle.cert.crmf.EncryptedValueBuilder;

import android.nfc.FormatException;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.Tag;
import android.nfc.tech.Ndef;

public class nfcUtils {

	private void write(Tag tag) throws IOException, FormatException {
	    NdefRecord[] records = { createRecord() };
	    NdefMessage  message = new NdefMessage(records);

	    // Get an instance of Ndef for the tag.
	    Ndef ndef = Ndef.get(tag);

	    // Enable I/O
	    ndef.connect();

	    // Write the message
	    ndef.writeNdefMessage(message);

	    // Close the connection
	    ndef.close();
	}
	
	private NdefRecord createRecord() throws UnsupportedEncodingException {
	    String text       = "Hello, World!";
	    String lang       = "pt";
	    byte[] textBytes  = text.getBytes();
	    byte[] langBytes  = lang.getBytes("US-ASCII");
	    int    langLength = langBytes.length;
	    int    textLength = textBytes.length;
	    byte[] payload    = new byte[1 + langLength + textLength];

	    // set status byte (see NDEF spec for actual bits)
	    payload[0] = (byte) langLength;

	    // copy langbytes and textbytes into payload
	    System.arraycopy(langBytes, 0, payload, 1,              langLength);
	    System.arraycopy(textBytes, 0, payload, 1 + langLength, textLength);

	    NdefRecord record = new NdefRecord(NdefRecord.TNF_WELL_KNOWN, 
	                                       NdefRecord.RTD_TEXT, 
	                                       new byte[0], 
	                                       payload);

	    return record;
	}
	
	/******************certificado digital**************/
	
	public void processaReciboCliente(String mRecibo){
		//RSa
	}
	
	
}
